<include file="Common/header" />
<title>新建网站角色</title>
<style>
	.picture_small_container{
		position:relative;
		float: left;
	}
	.small_delete{
		color: black;
		position:absolute;
		right:10px;top:10px;

	}
	.layui-upload-button{
		margin-right: 10px;
		float: left;
	}
</style>

</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">* </span>资讯标题：</label>
			<div class="formControls col-3">
				<input type="text" class="input-text radius" value="{$info['topic_title']}" placeholder="" id="topic_title" name="topic_title" datatype="*4-16" nullmsg="请输入资讯标题">
			</div>

			<label class="form-label col-2"><span class="c-red">* </span>资讯类型：</label>
			<div class="formControls col-3">
				<span class="select-box">
					<select class="select radius" name="topic_typeid" id="topic_typeid">
						<option value="0">--请选择类型--</option>
						<foreach name="typelist" item="types">
						<option value="{$types.typeid}" {$types['typeid'] == $info['topic_typeid'] ? 'selected' : ''}>{$types.type_title}</option>
						</foreach>
					</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">* </span>资讯内容：</label>
			<div class="formControls col-8">
				<script id="container" name="topic_content" type="text/plain">
					<?php echo html_entity_decode($info['topic_content']);  ?>
				</script>
				<!-- 配置文件 -->
				<script type="text/javascript" src="__APP__/lib/ueditor/ueditor.config.js"></script>
				<!-- 编辑器源码文件 -->
				<script type="text/javascript" src="__APP__/lib/ueditor/ueditor.all.js"></script>

			</div>
		</div>

		
		<!--<input type="hidden" id="topic_images" name="topic_images" value="" />-->
		<input type="hidden" id="topic_id" name="topic_id" value="{$info['topic_id']}" />
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<button type="button" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</div>



<!-- 加载编辑器的容器 -->

<script>
//实例化百度编辑器
//	window.UEDITOR_HOME_URL = "/lib/ueditor/";  //UEDITOR_HOME_URL、config、all这三个顺序不能改变
//	window.onload=function(){
//		window.UEDITOR_CONFIG.initialFrameHeight=300;//编辑器的高度
//		window.UEDITOR_CONFIG.imageUrl="__APP__/property/Upload/upload";          //图片上传提交地址
////		window.UEDITOR_CONFIG.imagePath=' /Uploads/thumb/';//编辑器调用图片的地址
//		UE.getEditor('contents');//里面的contents是我的textarea的id值
//	}
	<!-- 实例化编辑器 -->
	var ue = UE.getEditor('container'
//			{toolbars: [
//		[
//			'undo', //撤销
//			'bold', //加粗
//			'italic', //斜体
//			'underline', //下划线
//			'strikethrough', //删除线
//			'formatmatch', //格式刷
//			'selectall', //全选
//			'print', //打印
//			'link', //超链接
//			'unlink', //取消链接
//			'fontfamily', //字体
//			'fontsize', //字号
//			'simpleupload', //单图上传
//			'insertimage', //多图上传
//			'help', //帮助
//			'justifyleft', //居左对齐
//			'justifyright', //居右对齐
//			'justifycenter', //居中对齐
//			'justifyjustify', //两端对齐
//			'forecolor', //字体颜色
//			'backcolor', //背景色
//			'touppercase', //字母大写
//			'tolowercase', //字母小写
//		]
//	],
//			initialFrameHeight :320//高度
//			}
//			initialFrameWidth:700,//宽度

	);

	layui.use('upload', function(){
		layui.upload({
			url: '__APP__/property/Upload/upload' //上传接口
			,success: function(res){ //上传成功后的回调 console.log(res)
				if(res.status == true){
					//拼凑图片
					var pic = '<div class="picture_small_container" style="width: auto"><img src="__APP__/static/Uploads/'+res.file.savepath+res.file.savename+'" style="height: 110px;margin-right: 5px;margin-top: 5px" class="picture">';
					pic += "<input type='hidden' name='topic_images[]' class='topic_images' value='"+res.file.savepath+res.file.savename+"'/>";
					pic += "<a href='javascript:void(0)' onclick='delete_picture(this)' class='small_delete' style='color:red;font-weight: 200'>x</a></div>";
					//判断是否添加的图片已经超过数量
					var pic_num = $('.picture_small_container').length;
					if(pic_num == 6){
						layer.msg('图片最多6张，不能更多！',{icon:5,time:{$Think.config.PROMPT_TIME}});
						return false;
					}
					$('#pic_container').append(pic);
				}
			}
		});
	});

	//删除选中图片
	function delete_picture(obj){
		$(obj).parent().remove();
	}

	$(function(){
		$(".btn-success").on('click', function(){
			//验证参数
			if(!$("#topic_typeid").val()/1){
				layer.msg('请选择资讯类型');
				return false;
			}
			
			var topic_title = $("#topic_title").val() || '';
			if(!topic_title.length){
				layer.msg('请输入资讯标题');
				return false;
			}
			
//			var topic_content = $("#container").val() || '';
			var topic_content = ue.getContent() || '';
			if(!topic_content.length){
				layer.msg('请输入资讯内容');
				return false;
			}

			var topic_images = $(".topic_images").val() || '';
			if(!topic_content.length){
				layer.msg('请上传图片');
				return false;
			}

			//等待效果
			var load = layer.load(2);
			$.post('send.html', $("#form-user-character-add").serialize(), function(result){
				if(result.status == true){
					layer.msg(result.msg,{icon:1,time:{$Think.config.PROMPT_TIME}});
					setTimeout('parent.location.reload()',{$Think.config.PROMPT_TIME});
				}else{
					layer.msg(result.msg,{icon:5,time:{$Think.config.PROMPT_TIME}});
				}
			});
		});
	});
</script>
</body>
</html>